<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Basic ComboBox - jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../demo.css">

	<script type="text/javascript" src="../../jquery.min.js"></script>
	<script type="text/javascript" src="../../citiselect.js"></script>

	<script type="text/javascript" src="../../jquery.easyui.min.js"></script>



</head>
<body>
	<h2>Basic ComboBox</h2>
	<p>Type in ComboBox to try auto complete.</p>
	<div style="margin:20px 0"></div>
	<div class="easyui-panel" style="width:100%;max-width:400px;padding:30px 60px;">
		<div style="margin-bottom:20px">
			<select class="easyui-combobox" name="state" label="State:" labelPosition="top" style="width:100%;">
				<option value="AL">Alabama</option>
				<option value="AK">Alaska</option>
				<option value="AZ">Arizona</option>
			</select>
		</div>
	</div>
	<form id="ff" method="post">
		<table>
			<tbody>
			<tr>
				<td>
					<label for="province">省：</label>
				</td>
				<td>
					<input id="province" name="province" type="text" class="easyui-combobox"/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="city">市：</label>
				</td>
				<td>
					<input id="city" name="city" type="text" class="easyui-combobox"/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="county">区：</label>
				</td>
				<td>
					<input id="county" name="county" type="text" class="easyui-combobox"/>
				</td>
			</tr>
			</tbody>
		</table>
	</form>
<script>
	$(function () {
		//省市区三级联动
		$.citySelect({$province: $('#province'), $city: $('#city'), $County: $('#county')});
		$('#ff').form('load', {'province': '广东省', 'city': '深圳市', 'county': '罗湖区'});
	});

	$.extend($.fn.combobox.methods, {
		setIndex: function (jq, index) {
			if (!index)
				index = 0;
			var data = $(jq).combobox('options').data;
			var vf = $(jq).combobox('options').valueField;
			$(jq).combobox('setValue', eval('data[index].' + vf));
		},

		getIndex: function (jq) {
			var index = 0;
			var data = $(jq).combobox('options').data;
			var vf = $(jq).combobox('options').valueField;
			var value = $(jq).combobox('getValue');
			if (data != null && data.length != null) {
				for (var i = 0; i < data.length; i++) {
					if (value == eval('data[i].' + vf))
						index = i;
				}
			}
			return index;
		}
	});
</script>
</body>
</html>